package cn.tx.doubaodemo.common.exception;

import cn.tx.doubaodemo.common.result.IResult;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 全局异常处理类
 *
 * @author tx
 * @date 2022/8/29 14:55
 */
@RestControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(IException.class)
    public IResult<Object> handleCustomException(IException exception) {
        return IResult.fail(exception.getCode(), exception.getMessage());
    }

    @ExceptionHandler(Exception.class)
    public IResult<Object> handleException(Exception exception) {
        return IResult.fail(exception.getMessage());
    }


}
